package com.hcryan.djm.common.init;

import com.hcryan.djm.constant.LocationType;
import com.hcryan.djm.pojo.model.Location;
import com.hcryan.djm.service.AreaService;
import com.hcryan.djm.service.CityService;
import com.hcryan.djm.service.ProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ryanwdj
 * @since 2025/5/5
 */
@Component
public class LocationInitial {

    @Autowired
    private ProvinceService provinceService;
    @Autowired
    private CityService cityService;
    @Autowired
    private AreaService areaService;

    public static Map<LocationType, List<Location>> locationMap = new HashMap<>();

    @PostConstruct
    public void init() {
        List<Location> pLocation = provinceService.listProvince();
        List<Location> cLocation = cityService.listCity();
        List<Location> aLocation = areaService.listArea();

        locationMap.put(LocationType.PROVINCE, pLocation);
        locationMap.put(LocationType.CITY, cLocation);
        locationMap.put(LocationType.AREA, aLocation);
    }

    public static Map<LocationType, List<Location>> getLocationMap() {
        return locationMap;
    }

}
